package com.exception;

import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class GloableException /*implements HandlerExceptionResolver*/ {

    /*@Override
    public ModelAndView resolveException(
            HttpServletRequest request, HttpServletResponse response,
            Object handler, Exception ex) {

        ModelAndView mv = new ModelAndView("myerror");
        mv.addObject("msg",ex.getMessage());

        return mv;
    }*/

    @ExceptionHandler(value={java.lang.ArithmeticException.class})
    @ResponseBody
    public Map<String,Object> arithmeticExceptionHandler(Exception e){
        Map<String,Object> map = new HashMap<>();
        map.put("ex",e.getMessage());
        return map;
    }

}
